package com.cat.greedyAlgorithm;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-number-of-weeks-for-which-you-can-work/
 * @create 2025/10/12 16:02
 * @since JDK17
 */

public class Solution85 {
    public long numberOfWeeks(int[] milestones) {
        long sum = 0, max = 0;
        for (int num : milestones) {
            sum += num;
            max = Math.max(max, sum);
        }
        if (max > sum - max + 1) {  //
            return (sum - max) * 2 + 1;
        } else {
            return sum;
        }
    }
}
